﻿using iTextSharp.text;
using Microsoft.Office.Interop.Excel;
using Kingdee.BOS.Util;
using Org.BouncyCastle.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LanDBom.Models.price_New_2
{
    public class Find_P
    {
        LDbaseEntities LD = new LDbaseEntities();
        public List<libray> find_LengXing(string miaoshu)
        {
            List<libray> parices = LD.libray.Where(x => x.LB_fne == miaoshu).ToList();

            return parices;
        }
        public List<libray> find_Wastage_ProcessingCost(string miaoshu)
        {
            List<libray> parices = LD.libray.Where(x => x.LB_fne == miaoshu).ToList();
            return parices;
        }
        public List<libray> find_lib()
        {
            List<libray> librays = LD.libray.ToList();
            librays = librays.GroupBy(d => new { d.LB_fne }).Select(d => d.FirstOrDefault()).ToList();
            return librays;
        }
        public List<libray> find_lib(int s_id)
        {
            List<libray> librays = LD.libray.Where(x => x.ST_ID == s_id).ToList();
            return librays;
        }
        public List<libray> find_lib_id(int s_id)
        {
            libray librays = LD.libray.Where(x => x.LB_ID == s_id).First();
            int num= (int)librays.ST_ID;
            List<libray> libray2 = LD.libray.Where(x => x.ST_ID == num).ToList();
            return libray2;
        }
        public List<parice> find_manufacturer()
        {
            List<parice> parices = LD.parice.GroupBy(d => new { d.PA_LengBie }).Select(d => d.FirstOrDefault()).ToList();
            return parices;
        }
        public List<parice> find_parices()
        {
            List<parice> parices = LD.parice.ToList();

            return parices;
        }
        public List<parice> find_ZL_()
        {
            List<parice> parice = LD.parice.ToList();
            List<parice> parices = LD.parice.Where(s => s.PA_Shuxing == 3).ToList();

            return parices;
        }
        public List<parice> find_PKZ(string PP)
        {
            List<parice> parices = LD.parice.Where(x => x.PA_LengBie == PP).ToList();
            return parices;
        }
        public List<parice> find_DJ(string PP, string ZL)
        {
            List<parice> parices = LD.parice.Where(x => x.PA_Pinpai == PP && x.PA_ZhongL == ZL).ToList();
            return parices;
        }
        public List<parice> find_DJ(string lei)
        {
            List<parice> parices = LD.parice.Where(x => x.PA_ZhongL == lei).ToList();
            return parices;
        }
        public List<libray> find_JGF(string zl)
        {
            List<libray> librays = LD.libray.Where(x => x.LB_fne == zl).ToList();
            return librays;
        }
        public List<Formation> Find_formations()
        {
            List<Formation> formations = LD.Formation.ToList();
            return formations;
        }
        public List<mateial> find_mateial()
        {
            List<mateial> mateials = LD.mateial.ToList();
            return mateials;
        }
        public List<Projectpr> find_projectprs()
        {
            List<Projectpr> projectprs = LD.Projectpr.ToList();
            projectprs = projectprs.GroupBy(d => new { d.PR_name }).Select(a => a.OrderBy(b => b.PR_dai).ElementAt(0)).ToList();
            return projectprs;
        }
        public List<Projectpr> find_projectprs_2(string name)
        {
            List<Projectpr> projectprs = LD.Projectpr.Where(x=>x.PR_ZHong==name).ToList();
            projectprs = projectprs.GroupBy(d => new { d.PR_name }).Select(a => a.OrderBy(b => b.PR_dai).ElementAt(0)).ToList();
            return projectprs;
        }
        public List<Projectpr> find_projectprs(string name)
        {
            List<Projectpr> projectprs = LD.Projectpr.Where(x => x.PR_name == name).ToList();
            return projectprs;
        }
        public List<routing> find_Rou()
        {
            List<routing> projectprs = LD.routing.ToList();
            projectprs = projectprs.GroupBy(d => new { d.RO_hang }).Select(a => a.OrderBy(b => b.LB_ID).ElementAt(0)).ToList();
            return projectprs;
        }
        public List<routing> find_Rou_XS()
        {
            List<routing> projectprs = LD.routing.Where(x=>x.RO_hang=="吸塑").ToList();
            return projectprs;
        }
        public List<routing> find_Rou(string hang)
        {
            hang = hang == null ? "-1" : hang;
            List<routing> projectprs = LD.routing.Where(x => x.RO_hang == hang).ToList();
            return projectprs;
        }
        public List<routing> find_Rou_HC()
        {
            List<routing> projectprs = LD.routing.Where(x => x.RO_hang == "缓冲材").ToList();
            projectprs = projectprs.GroupBy(d => new { d.RO_kon }).Select(a => a.OrderBy(b => b.LB_ID).ElementAt(0)).ToList();
            return projectprs;
        }
        public List<routing> find_Rou_HC(string fp)
        {
            List<routing> projectprs = LD.routing.Where(x => x.RO_kon == fp).ToList();
            return projectprs;
        }

        public List<JiCheng> shenqin(string app_bian, string app_KHname, string app_xiang)
        {
            var jc = LD.JiCheng.ToList();
            if (app_bian!="")
            {
                jc=jc.Where(s=>s.JC_bianma.Contains(app_bian)).ToList();
            }
            if (app_KHname != "")
            {
                jc = jc.Where(s => s.JC_bianhao.Contains(app_KHname)).ToList();
            }
            if (app_xiang != "")
            {
                jc = jc.Where(s => s.JC_shen.Contains(app_xiang)).ToList();
            }
            return jc;
        }

        public List<Yunshu> YUNF()
        {
            var shinf = LD.Yunshu.ToList();
            return shinf;
        }

        public List<JICH> jicsin()
        {
            return LD.JICH.ToList();
        }
    }
}